package com.admin.business.portalWebsite.venusSysModelReport;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 范本举报表
 * @create: 2023-11-18 16:45:42
 **/
@Service("venusSysModelReportService")
@Slf4j
public class VenusSysModelReportService{

    @Resource
    VenusSysModelReportDao venusSysModelReportDao;

    /**
     * 添加范本举报表,获取id数据
     *
     * @param cdoRequest - id:主键id
     *                   - model_id:范本id
     *                   - report_user_id:举报人
     *                   - report_reason:举报原因
     *                   - handle_user_id:处理人
     *                   - handle_time:处理时间
     *                   - handle_state:范本状态(0处理中 1举报成功 2举报失败)
     *                   - handle_reason:处理意见
     *                   - begin_time:创建时间
     *                   - state:状态(0,正常 1,删除)
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return addVenusSysModelReport(CDO cdoRequest) {
        venusSysModelReportDao.addVenusSysModelReport(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新范本举报表数据
     *
     * @param cdoRequest - id:主键id
     *                   - model_id:范本id
     *                   - report_user_id:举报人
     *                   - report_reason:举报原因
     *                   - handle_user_id:处理人
     *                   - handle_time:处理时间
     *                   - handle_state:范本状态(0处理中 1举报成功 2举报失败)
     *                   - handle_reason:处理意见
     *                   - begin_time:创建时间
     *                   - state:状态(0,正常 1,删除)
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return updateVenusSysModelReportById(CDO cdoRequest) {
        venusSysModelReportDao.updateVenusSysModelReportById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除范本举报表数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return deleteVenusSysModelReportById(CDO cdoRequest){
        int count = venusSysModelReportDao.deleteVenusSysModelReportById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除范本举报表数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return deleteVenusSysModelReport(CDO cdoRequest) {
        int count = venusSysModelReportDao.deleteVenusSysModelReport(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取范本举报表数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return getVenusSysModelReportById(CDO cdoRequest) {
        CDO cdoMapperResult = venusSysModelReportDao.getVenusSysModelReportById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取范本举报表数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return getVenusSysModelReportListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysModelReportDao.getVenusSysModelReportListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysModelReportDao.getVenusSysModelReportCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取范本举报表数据列表
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return getVenusSysModelReportListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysModelReportDao.getVenusSysModelReportListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysModelReportDao.getVenusSysModelReportCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
